<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>登录-控制台</title>
    <link href="__PUBLIC__/assets/layui-2.4.5/css/layui.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/index.css" rel="stylesheet">

    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        html, body {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body class="login-body">
<div class="gWrap">
    <form class="layui-form" action="">
        <div class="view-item">
            <i class="layui-icon layui-icon-username"></i>
            <input type="text" name="username" placeholder="请输入账号">
        </div>
        <div class="view-item">
            <i class="layui-icon layui-icon-password"></i>
            <input type="password" name="password" placeholder="请输入密码">
        </div>
        <div class="view-item">
            <button class="layui-btn  layui-btn-radius layui-btn-normal layui-btn-fluid" lay-submit
                    lay-filter="loginBtn">立即提交
            </button>
        </div>
    </form>
</div>
<script src="__PUBLIC__/assets/layui-2.4.5/layui.js"></script>
<script src="__PUBLIC__/admin/js/common.js"></script>
<script src="__PUBLIC__/assets/md5/md5.min.js"></script>

<script>
    //Demo
    layui.use(['jquery', 'form', 'ajax'], function () {
        var common = layui.ajax //重点处
            , form = layui.form;

        //监听提交
        form.on('submit(loginBtn)', function (data) {
            if (!data.field.username) {
                layer.msg('账号不能为空');
                return false;
            }
            if (!data.field.password) {
                layer.msg('密码不能为空');
                return false;
            }
            // layer.msg(JSON.stringify(d));
            //发送ajax请求
            common.ajax({
                url: "/admin/login/dologin",
                type: "POST",
                dataType: "json",
                data: {username: data.field.username, password: md5(md5(data.field.username) + md5(data.field.password))},
                success: function (res) {
                    // console.log(res);
                    if (res.code === 1) {
                        window.location.href = res.data;
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>